using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class SysMembershipMap : EntityTypeConfiguration<SysMembership>
	{
		public SysMembershipMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.Id)
				.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
				
			this.Property(t => t.UserId)
				.IsRequired()
				.HasMaxLength(50);
				
			this.Property(t => t.Password)
				.HasMaxLength(100);
				
			this.Property(t => t.CreatedBy)
				.HasMaxLength(50);
				
			this.Property(t => t.ModifiedBy)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("SysMemberships");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.UserId).HasColumnName("UserId");
			this.Property(t => t.Password).HasColumnName("Password");
			this.Property(t => t.RoleId).HasColumnName("RoleId");
			this.Property(t => t.IsApproved).HasColumnName("IsApproved");
			this.Property(t => t.CreatedOn).HasColumnName("CreatedOn");
			this.Property(t => t.CreatedBy).HasColumnName("CreatedBy");
			this.Property(t => t.ModifiedOn).HasColumnName("ModifiedOn");
			this.Property(t => t.ModifiedBy).HasColumnName("ModifiedBy");

			// Relationships
			this.HasRequired(t => t.SysRole)
				.WithMany(t => t.SysMemberships)
				.HasForeignKey(d => d.RoleId);
				
		}
	}
}

